package top.leyi.handle;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.leyi.IService.IJobjService;
import top.leyi.entity.Job;
import top.leyi.entity.user.User;
import top.leyi.utils.Result;
import top.leyi.utils.ResultGenerator;


@RestController
@RequestMapping("/api/job")
public class JobHandle {
    @Autowired
    IJobjService jobjService;
    @GetMapping("/{page}")
    public Result doGet(
                        @PathVariable("page") int page,
                        @RequestParam("token") String token ) {
        User user = new User();
        return new Result(200, jobjService.queruAllJobs(page, user));
    }


    @PostMapping
    public Result doPost(@RequestParam("token") String token,
                        @RequestParam("name") String name,
                         @RequestParam("pics") String pics,
                         @RequestParam("phone") String phone,
                         @RequestParam("details") String details,
                        @RequestParam("id") int id) {

        Job job = new Job();
        job.setDetails(details);
        job.setName(name);
        job.setPics(pics);
        job.setPhone(phone);
        User user = new User();
        user.setId(id);
        jobjService.addJob(job, user);
        return ResultGenerator.OK.getResult();
    }

    @DeleteMapping
    public Result doDel(@RequestParam("token") String token,
                        @RequestParam("userId") int userId,
                        @RequestParam("id") int id
                        ) {
          Job job = new Job();

          User user = new User();
          user.setId(userId);
          job.setId(id);
          jobjService.deleteJob(job, user);
          return ResultGenerator.OK.getResult();
     }

  }
